$(function(){

    var doc=document,
        UserForm=doc.getElementById('UserForm'),
        error=$('.error'),
        button=$('input[type=button]'),
        success=$('.success');
    var input={
        custom_name:UserForm.custom_name,
        account:UserForm.account,
        phone:UserForm.phone,
        custom_address:UserForm.custom_address,
        reg_time:UserForm.reg_time,
        pid:UserForm.pid,
        update:UserForm.update,
    }
    $('input').on('focus',function(){
        error.text('');
        success.text('');
    })
    button.on('click',function(){

        var value={
            custom_name:$.trim(input.custom_name.value),
            account:$.trim(input.account.value),
            phone:$.trim(input.phone.value),
            custom_address:$.trim(input.custom_address.value),
            reg_time:$.trim(input.reg_time.value),
            pid:$.trim(input.pid.value),
            update:$.trim(input.update.value)
        }

        if(!value.custom_name || !value.account ){
            error.text('信息填写不能为空');
            return ;
        }

        this.classList.add('disabled');
        this.value='处理中..';
        var self=this;

        if(this.classList.contains('disabled')){
            $.post('/api/add_custom',value).then(function(data){
                if(data.fail){
                    self.classList.remove('disabled')
                    layer.msg(data.msg, {icon: 2});
                    self.value='保存';
                    return ;
                }
                if(data.success){
                    layer.alert(data.msg,{}, function(index){
                        layer.close(index);
                        self.classList.remove('disabled');
                        self.value='保存';
                    });
                }
            })
        }



    })

})